all files / applications/kapcsolat/ kapcsolat-popup.js

0% Statements 0/36
0% Branches 0/12
0% Functions 0/15
0% Lines 0/36
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                                                                                                                                                     
export default class KapcsolatPopupController {
	constructor(kapcsolatService, $scope) {
		'ngInject';
		this._kapcsolatService = kapcsolatService;
		this._$scope = $scope;
		this.bevetelek = [
			'0-50 M Ft-ig',
			'50-100 M Ft-ig',
			'100-500 M Ft-ig'
		];
		this.model = {
			ceg: false
		};
		this._$scope.$watch('$ctrl.kivalasztottSzolgaltatasok', () => {
			this.model.szolgaltatas = [];
			angular.forEach(this.kivalasztottSzolgaltatasok, (value, key) => {
				if (value) {
					this.model.szolgaltatas.push(key);
				}
			});
		}, true);
		this._$scope.$watch('$ctrl.model.ceg', (newVal) => {
			if (newVal) {
				this.model.nev = '';
			} else {
				this.model.cegNev = '';
			}
		});
		this._getSzolgaltatasok();
		this.captchaUrl = this._getCaptchaUrl();
	}
	_getSzolgaltatasok() {
		this._kapcsolatService.getSzolgaltatasok().then((response) => {
			this.szolgaltatasok = response;
		}, () => {
			this.technikaiHiba = true;
		});
	}
	getVarosokByIrszam() {
		this._kapcsolatService.getVarosokByIrszam(this.model.iranyitoszam).then((response) => {
			this.varosok = response;
			if (this.varosok.length==1) {
				this.model.varos = this.varosok[0];	
			} else {
				this.model.varos = '';
			}
		}, () => {
			this.technikaiHiba = true;
		});
	}
	kuldes(e) {
		e.preventDefault();
		this._kapcsolatService.kuldes(this.model, this.captcha).then(() => {
			this._captchaFrissites();
			this.captcha = '';
			this.success = true;
		}, (err) => {
			if (err.status && err.status == 400 && err.data && err.data.errors) {
				this.errors = err.data.errors;
			} else {
				this.technikaiHiba = true;
			}
			this._captchaFrissites();
			this.captcha = '';
		});
 
	}
	_captchaFrissites() {
		this.captchaUrl = this._getCaptchaUrl();
	}
	_getCaptchaUrl() {
		return this._kapcsolatService.getCaptchaUrl();
	}
}